import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

class Worker extends Thread{
    private BlockingQueue<Runnable> queue = null;

    public Worker(BlockingQueue<Runnable> queue){
        this.queue = queue;
    }

    @Override
    public void run() {
        while (true) {
            try {
                Runnable command = queue.take();
                command.run();
            }catch (InterruptedException e){
                e.printStackTrace();
            }
        }
    }
}
class MyThreadPool{
    private BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>();

    private List<Worker> workers = new ArrayList<>();

    private final int MAX_WORKER_COUNT = 10;

    public void submit(Runnable command) throws InterruptedException {
        if(workers.size() < MAX_WORKER_COUNT){
            Worker worker = new Worker(queue);
            worker.start();
            workers.add(worker);
        }
        queue.put(command);
    }
}